import java.awt.EventQueue;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JLabel;


public class Main {

	private JFrame frame;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Main window = new Main();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}


	public Main() {
		initialize();
	}


	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 741, 721);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
		final JTextArea textArea = new JTextArea();
		JScrollPane scrollCodigo = new JScrollPane(textArea);
		scrollCodigo.setBounds(0, 0, 647, 671);
		frame.getContentPane().add(scrollCodigo);
		textArea.setBounds(0, 0, 647, 671);
//		frame.getContentPane().add(textArea);
		
		final JLabel lb = new JLabel("");
		lb.setBounds(649, 11, 66, 31);
		frame.getContentPane().add(lb);
		
		final JLabel lblNewLabel = new JLabel("");
		lblNewLabel.setBounds(649, 53, 66, 31);
		frame.getContentPane().add(lblNewLabel);
		
		textArea.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent arg0) {
				if(!textArea.getText().equals("")){
					int start = textArea.getSelectionStart();
					int fim = textArea.getSelectionEnd();
					
					String texto = textArea.getText();
//					String subTexto = texto.substring(textArea.getSelectionStart(), textArea.getSelectionEnd());
					int numeroEnters = 0;
					int numeroEnters2 = 0;
					
					char[] caracteres = texto.toCharArray();
					
					for(int i = 0; i < start; i++){
						if(caracteres[i] == '\n' || caracteres[i] == '\t'){
							numeroEnters++;
						}
					}
					start += (numeroEnters * 1);
					
					
					for(int i = start; i < fim; i++){
						if(caracteres[i] == '\n' || caracteres[i] == '\t'){
							numeroEnters2++;
						}
					}
					
					fim += (numeroEnters2 * 1 + numeroEnters + 2);
					
					lb.setText(String.valueOf(start));
					lblNewLabel.setText(String.valueOf(fim));
					
					TextTransfer t = new TextTransfer();
					t.setClipboardContents("\ntaController.markText("+lb.getText()+", "+lblNewLabel.getText()+");");
				}
			}
			
			@Override
			public void mousePressed(MouseEvent arg0) {
				
			}
			
			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
		});
	}
}
